package com.youi.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.dao.SysuserDao;
import com.youi.entity.Merchant;
import com.youi.entity.Sysrole;
import com.youi.entity.Sysuser;
import com.youi.service.MerchantService;
import com.youi.service.SysroleService;
import com.youi.service.SysuserService;

@Service
public class SysuserServiceImpl extends BaseServiceImpl<Sysuser> implements SysuserService{
		
		private SysuserDao sysuserDao;
		@Autowired
		private MerchantService merchantService;
		@Autowired
		private SysroleService sysroleService;
		@Autowired
		public void setfaultRecordDao(SysuserDao sysuserDao){
			this.sysuserDao=sysuserDao;
			super.setBaseDAO(sysuserDao);
		}

		@Override
		public List<Sysuser> getSysuserList(Map<String, Object> params, Map<String, Object> notParams,
				Map<String, Object> searchParams, Map<String, Object> sortParams, Integer pageIndex, Integer pageNum,
				Map<String, Object> gtParams, Map<String, Object> ltParams) {
			// TODO Auto-generated method stub
			return sysuserDao.getSysuserList(params, notParams, searchParams, sortParams, pageIndex, pageNum, gtParams, ltParams);
		}

		@Override
		public void getSysuserMsg(Sysuser sysuser) {
			// TODO Auto-generated method stub
			if (sysuser!=null) {
				Map<String, Object> prams=new HashMap<String, Object>();
				prams.put(Common.DELSTATUS, DelStatus.NODEL);
				prams.put(Common.ID, sysuser.getMerchantId());
				Merchant merchant=merchantService.getByParam(prams);
				if (merchant!=null) {
					sysuser.setMerchantName(merchant.getShortName());
				}
				Sysrole sysrole=sysroleService.get(sysuser.getRoleId());
				if (sysrole!=null) {
					sysuser.setSysrolePms(sysrole.getPms());
					sysuser.setSysroleName(sysrole.getName());
				}
			}
		}

		@Override
		public void getSysuserMsg(List<Sysuser> sysuserList) {
			// TODO Auto-generated method stub
			if (sysuserList!=null&&sysuserList.size()>0) {
				for (Sysuser sysuser : sysuserList) {
					getSysuserMsg(sysuser);
				}
			}
		}
}